package org.example.processor;
import lombok.extern.slf4j.Slf4j;
import org.deeplearning4j.nn.graph.ComputationGraph;
import org.deeplearning4j.zoo.PretrainedType;
import org.deeplearning4j.zoo.model.VGG16;
import org.deeplearning4j.zoo.ZooModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
@Slf4j
@Configuration
public class FeatureExtractor {
//    @PostConstruct
    @Bean
    public ComputationGraph loadModel() {
        try {
            System.setProperty("org.bytedeco.javacpp.logger.debug", "true"); // 开启下载日志
            // 直接加载DeepLearning4j内置的VGG16模型
            ZooModel zooModel = VGG16.builder().build();
            System.out.println("真实模型下载地址：" + zooModel.pretrainedUrl(PretrainedType.IMAGENET));
            ComputationGraph model = (ComputationGraph) zooModel.initPretrained();
            return model;
        } catch (IOException e) {
            log.error("模型下载失败{}",e);
            return null;
        }
    }
}
